package com.great.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.great.dao.UserCollectionMapper;
import com.great.dao.UserInfoMapper;
import com.great.model.pojo.UserInfo;
import com.great.service.IUserInfoService;
@Service
public class UserInfoServiceImpl  implements IUserInfoService{
	@Resource
	private UserInfoMapper userInfoMapper;
	@Resource
	private UserCollectionMapper userCollectionMapper;
	@Override
	public void sAddUser(UserInfo userInfo) {
		userInfoMapper.addUser(userInfo);
	}
	@Override
	public List<UserInfo> sSelectUser(String selectStr) {
		List<UserInfo> userInfos=null;
		if (selectStr.equals("")) {
			userInfos=userInfoMapper.selectAllUser();
		}else {
			userInfos=userInfoMapper.selectUser(selectStr);
		}
		return userInfos;
	}

	@Override
	public String sRegister(UserInfo userInfo) {
		List<UserInfo> userInfos=null;
		userInfos=userInfoMapper.selectUser(userInfo.getUserNumber());
		if(userInfos.size()==0)
		{
			userInfo.setUserCore(0);
			userInfoMapper.addUser(userInfo);
			return "注册成功!";
		}else {
			return "该账号已经存在!";
		}
	}
	@Override
	public String sLoginYZ(UserInfo userInfo) {
		List<UserInfo> userInfos=null;
		userInfos=userInfoMapper.selectUserByNumberAndPassword(userInfo);
		if(userInfos.size()>0)
		{
			return "验证成功!";
		}else {
			return "用户账号和密码错误!";
		}
	}
	@Override
	public UserInfo sLogin(UserInfo userInfo) {
		List<UserInfo> userInfos=null;
		userInfos=userInfoMapper.selectUserByNumberAndPassword(userInfo);
		if(userInfos.size()>0)
		{
			return userInfos.get(0);
		}else {
			return null;
		}
	}
	@Override
	public String suserNumberExistYZ(UserInfo userInfo) {
		try {
			List<UserInfo> userInfos=userInfoMapper.selectUser(userInfo.getUserNumber());
			if (userInfos.size()>0) {
				return "exist";
			}
			return "noexist";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
	
	
	@Override
	public void sUpdataUser(UserInfo userInfo) {
			userInfoMapper.updataUser(userInfo);		
	}
	@Override
	public void sDeleteUser(UserInfo userInfo) {
		userCollectionMapper.delectUserCollection(userInfo);
		userInfoMapper.deleteUser(userInfo);
	}
	public UserInfoMapper getUserInfoMapper() {
		return userInfoMapper;
	}
	public void setUserInfoMapper(UserInfoMapper userInfoMapper) {
		this.userInfoMapper = userInfoMapper;
	}
	public UserCollectionMapper getUserCollectionMapper() {
		return userCollectionMapper;
	}
	public void setUserCollectionMapper(UserCollectionMapper userCollectionMapper) {
		this.userCollectionMapper = userCollectionMapper;
	}
	
	
}
